package com.interrupt;

public class InterruptExample {


    /**
     * 通过调用一个线程的interrupt（）中断该线程，如果该线程处于阻塞，限期等待或者无限期等待状态，那么会抛出InterruptedException,从而提前结束改线程，但不能中断I/O阻塞和synchronized所阻塞。
     */
    private static  class  MyThread1 extends Thread{
        @Override
        public void run(){
            try {
                Thread.sleep(2000);
                System.out.println("Thread run");

            }catch (InterruptedException e){
                e.printStackTrace();
            }
        }
    }

    public static void main(String[] args) {
        Thread thread1=new MyThread1();
        thread1.start();
        thread1.interrupt();
        System.out.println("Main run");
    }

}
